const Router = require('koa-router')

const router = new Router({ prefix: '/user' })
const { auth } = require('../middleware/auth_middleware')
//注入控制器方法
const { register, login,
    sendEmail, changePassword,
    updateInfo, removePicture,
    uploadFileTest, uploadImage,
    UpdateInfo, updateUserImportInfo,
    selectUser, UserInfo
} = require('../controller/user_controller')

const { userVaildator, crpytPassword,
    userInfoVaildator, loginVaild,
    emailVaildtor, userNicknameVaild,
    userinfoVaild, rawPasswordVaild,
    emailChecked, uploadFile,
    findRawimagekey, userPwdVaildator,
    usernickname
} = require('../middleware/user_middleware')

router.get('/', (ctx, next) => {
    ctx.body = "测试"
})

//用户注册
//验证完邮箱验证码后加验证 请求图床
router.post('/sign', uploadFile, userVaildator, userNicknameVaild, emailVaildtor, emailChecked, uploadFileTest, crpytPassword, register)

//登录
router.post('/login', userInfoVaildator, loginVaild, login)

//用户发送邮箱
//发送邮箱验证码
router.post('/getEamilCode', emailVaildtor, sendEmail)

//用户更新密码或信息 
router.post('/ptinfo', auth, userNicknameVaild, userPwdVaildator, rawPasswordVaild, crpytPassword, updateUserImportInfo)

//更新用户头像
router.post('/Upimage', auth, uploadFile, findRawimagekey, uploadFileTest, uploadImage, removePicture)

//删除照片
router.get('/remove', removePicture, findRawimagekey)

//根据token获取最新消息
router.get('/auth', auth, UpdateInfo)

//查找用户 
router.get('/selectFriend', auth, usernickname, selectUser)

//根据id查找
router.get('/getinfo', auth, UserInfo)

//用户找回密码
// router.patch('/unknownPwd',)
module.exports = router